package com.jin.六大设计原则.迪米特法则.违背;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* 通过校长管理所有学生，老师只是提供了非常简单的信息，虽然可以查询到结果，但是违背了迪米特法则（高内聚低耦合）
* 因为校长需要了解每个学生的情况，如果所有的班级都要校长统计，代码会变得非常的臃肿，不利于后续的管理以及维护
* */
public class Principal {
    private Teacher teacher = new Teacher("李立辉","幼稚园3班");
    //查询班级信息，总分，学生人数，平均分
    public Map<String,Object> queryClazzInfo(String clazzId){
        //获取班级信息：学生人数，总分，平均分
        int stuCount = clazzStudentCount();
        double totalScore = clazzTotalScore();
        double averageScore = clazzAverageScore();

        //组装对象
        HashMap<String, Object> mapObj = new HashMap<>();
        mapObj.put("班级",teacher.getClazz());
        mapObj.put("老师姓名",teacher.getName());
        mapObj.put("学生人数",stuCount);
        mapObj.put("总分",totalScore);
        mapObj.put("平均分",averageScore);
        return mapObj;
    }

    //总分
    public double clazzTotalScore(){
        double totalScore = 0;
        List<Student> studentList = Teacher.getStudentList();
        for (Student student : studentList) {
            totalScore=totalScore+student.getGrade();
        }
        return totalScore;
    }

    //平均分
    public double clazzAverageScore(){
        double totalScore = 0;
        List<Student> studentList = Teacher.getStudentList();
        for (Student student : studentList) {
            totalScore=totalScore+student.getGrade();
        }
        return totalScore/Teacher.getStudentList().size();
    }

    //班级人数
    public int clazzStudentCount(){
        return Teacher.getStudentList().size();
    }
}
